<?php
namespace Core;

/**
* Service access layer class
*/
class CoreService
{
	/**
	* @property IAccounts $IAccounts The accounts module
	*/
	private $IAccounts;
	
	/**
	* @property IDocuments $IDocuments The documents module
	*/
	private $IDocuments;
	
	/**
	* @property IOperations $IOperations The operations module
	*/
	private $IOperations;
	
	/**
	* @property ICategories $ICategories The categories module
	*/
	private $ICategories;
	
	/**
	* @property ITasks $ITasks The tasks module
	*/
	private $ITasks;
	
	/**
	* @property IUsers $IUsers The users module
	*/
	private $IUsers;
	
	/**
	* @property IArticles $IArticles The articles module
	*/
	private $IArticles;
	
	/**
	* @property IArticles $IArticles The articles module
	*/
	private $IEvents;
	
	/**
	* @property ITchats $ITchats The tchat module
	*/
	private $ITchats;
	
	/*
	* @property IMaterials $IMaterials The logistic module
	*/
	private $IMaterials;
	
	/**
	* @property string $documentRootPath The document root path
	*/
	private $documentRootPath;
	
	/**
	* @property string $archiveRootPath The archive root path
	*/
	private $archiveRootPath;
	
	/**
	 * Default constructor
	 */
	public function __construct()  
    {
		$this->IAccounts = new CoreComponents\AccountingManager\Accounts();
		$this->IDocuments = new CoreComponents\DocumentsManager\Documents();
		$this->IOperations = new CoreComponents\AccountingManager\Operations();
		$this->ICategories = new CoreComponents\AccountingManager\Categories();
		$this->ITasks = new CoreComponents\TasksManager\Tasks();
		$this->IUsers = new CoreComponents\UsersManager\Users();
		$this->IArticles = new CoreComponents\ArticlesManager\Articles();
		$this->IEvents = new CoreComponents\EventsManager\Events();
		$this->ITchats = new CoreComponents\TchatsManager\Tchats();
		$this->IMaterials = new CoreComponents\LogisticManager\Materials();
		
		$parameters = CoreCommons\Parameters::Singleton();
		$rootPath = $parameters::Get("documentsrootpath");
		$this->documentRootPath = __dir__ . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . $rootPath;
		
		if(file_exists($this->documentRootPath) == false)
		{
			mkdir($this->documentRootPath);
		}
		
		$archiveRootPath = $parameters::Get("archivesrootpath");
		$this->archiveRootPath = __dir__ . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . $archiveRootPath;
		
		if(file_exists($this->archiveRootPath) == false)
		{
			mkdir($this->archiveRootPath);
		}
    }
	
	/**
	 * Add an account
	 *
	 * @param integer $state The account state
	 * @param string $name The account name
	 *
	 * @return ServiceResponse This response contains the added account
	 */
	public function addAccount($state, $name)
	{
		return $this->IAccounts->addAccount($state, $name);
	}
	
	/**
	 * Get all accounts
	 * 
	 * @return ServiceResponse This response contains all accounts
	 */
	public function getAccounts()
	{
		return $this->IAccounts->getAccounts();
	}
	
	/**
	 * Update an account
	 *
	 * @param integer $id The unique identifier of the account
	 * @param string $name The account name
	 * @param string $state The account state
	 *
	 * @return ServiceResponse This response contains the updated account
	 */
	public function updateAccount($id, $name, $state)
	{
		return $this->IAccounts->updateAccount($id, $name, $state);
	}
	
	/**
	 * Delete an account
	 * 
	 * @param string $name The account name 
	 *
	 * @return null
	 */
	public function deleteAccount($name)
	{
		return $this->IAccounts->deleteAccount($name);
	}
	
	/**
	 * Get an account by name
	 * 
	 * @param string $name The account name 
	 *
	 * @return ServiceResponse This response contains the the account
	 */
	public function getAccount($name)
	{
		return $this->IAccounts->getAccount($name);
	}
	
	/**
	 * Get all documents from root
	 *
	 * @param string $root The document root path to parse
	 * @param boolean $forceToRefresh Force to refresh the cache
	 * @param string $filter The filter search request
	 *
	 * @return ServiceResponse This response contains all documents found on the provided path
	 */
    public function getRecursiveDocuments($root, $forceToRefresh, $filter)
	{
		return $this->IDocuments->getRecursiveDocuments($this->documentRootPath, $forceToRefresh, $filter);
	}
	
	/**
	 * Get all documents from root
	 *
	 * @param string $root The document root path to parse
	 * @param boolean $forceToRefresh Force to refresh the cache
	 * @param string $filter The filter search request
	 *
	 * @return ServiceResponse This response contains all documents found on the provided path
	 */
    public function getDocuments($root, $forceToRefresh, $filter)
	{
		if($root == "")
		{
			$root = $this->documentRootPath;
		}
		
		return $this->IDocuments->getDocuments($root, $forceToRefresh, $filter);
	}
	
	/**
	 * Get the number of documents from root
	 * 
	 * @param string $root The document root path to parse
	 *
	 * @return ServiceResponse The response contains the number of documents found
	 */
    public function getDocumentsCount($root)
	{
		return $this->IDocuments->getDocumentsCount($this->documentRootPath);
	}
	
	/**
	 * Upload document
	 * 
	 * @param string $tempPath The temporary path to copy the file
	 * @param string $dirPath The directory path to copy the file
	 * @param string $filename The file name to copy the file
	 *
	 * @return ServiceResponse The response contains the created document
	 */
    public function uploadDocument($tempPath, $dirPath, $filename)
	{
		return $this->IDocuments->uploadDocument($tempPath, $dirPath, $filename);
	}
	
	/**
	 * Create a temporary document on the server in order to download it
	 * 
	 * @param string $sourcePath The source path to create the temporary document
	 *
	 * @return ServiceResponse the response contains the created temporary document
	 */
    public function createTempDocument($sourcePath)
	{
		//Copy the targetted file on server temp directory
		$this->IDocuments->createTempDocument($sourcePath);
		
		//return url to download
		$parameters = CoreCommons\Parameters::Singleton();
		$tempUrl = $parameters::$Keys["TempUrl"];
		
		$filename = basename($sourcePath);
		return $tempUrl . $filename;
	}
	
	/**
	 * Create a temporary file to download
	 * 
	 * @param string $sourcePath The path to the targeted document 
	 * 
	 * @return ServiceResponse The response contains the new temporary document 
	 */
    public function createTempAttachmentFromBinary($eventAttachmentId, $attachmentName)
	{
		$result = null;
	
		//Get the event attachment
		$eventAttachmentResult = $this->IEvents->getEventAttachment($eventAttachmentId);
		
		if($eventAttachmentResult->isFailed == false)
		{
			//Copy the targetted file on server temp directory
			$pathResult = $this->IDocuments->createTempDocumentFromBinary($eventAttachmentResult->response->AttachmentName, $eventAttachmentResult->response->AttachmentExtension, $eventAttachmentResult->response->Attachment);
			
			if($pathResult->isFailed == false)
			{
				//Return url to download
				$parameters = CoreCommons\Parameters::Singleton();
				$tempUrl = $parameters::$Keys["TempUrl"];
				$filename = basename($pathResult->response);
				$result = $tempUrl . $filename;
			}
		}
		
		return $result;
	}
	
	/**
	* Delete an event attachment
	* 
	* @param integer $eventId The unique event identifier
	*
	* @return ServiceResponse This response contains all event attachments
	*/
	public function deleteEventAttachment($id)
	{
		return $this->IEvents->deleteEventAttachment($id);
	}
	
	/**
	 * Delete document
	 * 
	 * @param string $path The path to delete the document
	 *
	 * @return ServiceResponse The response contains the deleted document
	 */
    public function deleteDocument($path)
	{
		return $this->IDocuments->deleteDocument($path);
	}
	
	/**
	 * Delete archive
	 * 
	 * @param string $path The path to delete the archive
	 *
	 * @return ServiceResponse The response contains the deleted archive
	 */
    public function deleteArchive($path)
	{
		return $this->IDocuments->deleteDocument($path);
	}
	
	/**
	 * Rename document
	 *
	 * @param string $path The path to rename the document
	 * @param string $newName The new name of the document
	 * @param string $oldName The old name of the document
	 * 
	 * @return ServiceResponse The response provide the renamed document
	 */
    public function renameDocument($path, $newName, $oldName)
	{
		return $this->IDocuments->renameDocument($path, $newName, $oldName);
	}
	
	/**
	 * Create a folder
	 * 
	 * @param string $path The path of the folder
	 * @param string $name The name of the folder
	 *
	 * @return ServiceResponse The response contains the created folder
	 */
    public function createFolder($path, $name)
	{	
		if($path == null ||$path == '')
		{
			$path = $this->documentRootPath;
		}
		
		return $this->IDocuments->createFolder($path, $name);
	}
	
	/**
	 * Create an archive
	 * 
	 * @param string $archiveName The archive name
	 *
	 * @return ServiceResponse The response contains the created archive
	 */
	public function createArchive($archiveName, $eventReference)
	{
		$this->attachArchive($eventReference, $archiveName);
	
		return $this->createFolder($this->archiveRootPath, $archiveName);
	}
	
	/**
	 * Rename archive
	 *
	 * @param string $newName The new name of the archive
	 * @param string $oldName The old name of the archive
	 * 
	 * @return ServiceResponse The response provide the renamed archive
	 */
    public function renameArchive($newName, $oldName)
	{
		return $this->IDocuments->renameDocument($this->archiveRootPath, $newName, $oldName);
	}
	
	/**
	 * Get all archives from archives root
	 *
	 * @param boolean $forceToRefresh Force to refresh the cache
	 * @param string $filter The filter search request
	 *
	 * @return ServiceResponse This response contains all documents found on the provided path
	 */
    public function getArchives($path, $forceToRefresh, $filter)
	{
		if($path == "")
		{
			$path = $this->archiveRootPath;
		}
		
		$path = str_replace("\\", "/" , $path);
		
		CoreCommons\Logger::Info("getArchives $path, $forceToRefresh, $filter");
	
		return $this->IDocuments->getDocuments($path, $forceToRefresh, $filter);
	}
	
	/**
	 * Get all operations from an account
	 * 
	 * @param integer $accountId The unique identifier of the account
	 * @param datetime $startDate The start date time 
	 * @param datetime $endDate The end date time 
	 *
	 * @return ServiceResponse The response contains all operations between start date and end date
	 */
    public function getOperations($accountId, $startDate, $endDate)
	{
		return $this->IOperations->getOperations($accountId, $startDate, $endDate);
	}
	
	/**
	 * Get an operation by his Id
	 * 
	 * @param integer $id The unique identifier of the operation
	 *
	 * @return ServiceResponse The response contains the targeted operation
	 */
    public function getOperation($id)
	{
		return $this->IOperations->getOperation($id);
	}
	
	/**
	 * Add an operation
	 *
	 * @param string $label The label description of the operation
	 * @param integer $type The type of the operation
	 * @param integer $status The status of the operation
	 * @param integer $paymentMean The payment mean of the operation
	 * @param integer $category The category related to the operation
	 * @param float $expectedamount The expected amount for this operation
	 * @param datetime $operationdate The operation date treated on the account
	 * @param boolean $isRecurring Is the operation recurring
	 * @param float $realamount The real amount performed on the account. This is an optional parameter, for rejected operation case
	 *
	 * @return ServiceResponse The response contains the added operation
	 */
	public function addOperation($accountId, $label, $type, $status, $paymentMean, $category, $expectedamount, $operationdate, $isRecurring, $realamount = null)
	{
		return $this->IOperations->addOperation($accountId, $label, $type, $status, $paymentMean, $category, $expectedamount, $operationdate, $isRecurring, $realamount = null);
	}
	
	/**
	 * Update an operation
	 *
	 * @param integer $id The unique identifier of the operation
	 * @param string $label The label description of the operation
	 * @param integer $type The type of the operation
	 * @param integer $status The status of the operation
	 * @param integer $paymentMean The payment mean of the operation
	 * @param integer $category The category related to the operation
	 * @param float $expectedamount The expected amount for this operation
	 * @param float $realamount The real amount for this operation
	 * @param datetime $operationdate The operation date treated on the account
	 * @param boolean $isRecurring Is the operation recurring
	 *
	 * @return ServiceResponse The response contains the updated operation
	 */
	public function updateOperation($id, $label, $type, $status, $paymentMean, $category, $expectedamount, $realamount, $operationdate, $isRecurring)
	{
		return $this->IOperations->updateOperation($id, $label, $type, $status, $paymentMean, $category, $expectedamount, $realamount, $operationdate, $isRecurring);
	}
	
	/**
	 * Attach a bill to an operation
	 * 
	 * @param Operation $operation An operation object
	 *
	 * @return ServiceResponse This response contains the updated operation
	 */
	public function attachBill($operation)
	{
		return $this->IOperations->attachBill($operation);
	}
	
	/**
	 * Delete an operation
	 * 
	 * @param integer $id The unique identifier of the operation to delete
	 *
	 * @return ServiceResponse The response contains a boolean to know if it's delete
	 */
    public function deleteOperation($id)
	{
		return $this->IOperations->deleteOperation($id);
	}
	
	/**
	 * Get all categories from an account
	 *
	 * @param string $accountName The account name to get his categories
	 * @todo This method should use the account identifier instead of the account name 
	 *
	 * @return ServiceResponse This response contains all categories from account
	 */
    public function getCategories($accountName)
	{
		return $this->ICategories->getCategories($accountName);
	}
	
	/**
	 * Get category from an account and a name
	 * 
	 * @param string $accountName The account name to get his categories
	 * @param string $categoryName The category name targeted
	 * @todo This method should use the account identifier instead of the account name 
	 * @todo This method should use the category identifier instead of the category name 
	 *
	 * @return ServiceResponse This response contains the category from account
	 */
    public function getCategorie($accountName, $categoryName)
	{
		return $this->ICategories->getCategorie($accountName, $categoryName);
	}
	
	/**
	 * Get category form an id
	 * 
	 * @param integer $id The account unique identifier of the category
	 *
	 * @return ServiceResponse This response contains the category
	 */
    public function getCategorieFromId($id)
	{
		return $this->ICategories->getCategorieFromId($id);
	}
	
	/**
	 * Add a category
	 * 
	 * @param string $accountName The account name
	 * @param string $name The name of the category
	 * @param integer $parentId The parent category id, it can be null or 0.
	 *
	 * @return ServiceResponse This response contains the added category
	 */
    public function addCategory($accountName, $name, $parentId)
	{
		return $this->ICategories->addCategory($accountName, $name, $parentId);
	}
	
	/**
	 * Delete a category
	 * 
	 * @param integer $id The account unique identifier of the category
	 *
	 * @return ServiceResponse This response contains a boolean to know if the category has been deleted
	 */
    public function deleteCategory($id)
	{
		return $this->ICategories->deleteCategory($id);
	}
	
	/**
	 * Synchronize categories to folders
	 * 
	 * @param integer $idAccount The account unique identifier
	 *
	 * @return ServiceResponse This response contains a boolean to know if the categories has been synchronized
	 */
    public function synchronizeCategoriesToFolders($idAccount)
	{
		$parameters = CoreCommons\Parameters::Singleton();
		$rootPath = $parameters::$Keys["DocumentsRootPath"];
		
		return $this->ICategories->synchronizeCategoriesToFolders($idAccount, $rootPath);
	}
	
	/**
	 * Synchronize folders to categories
	 * 
	 * @param integer $idAccount The account unique identifier
	 *
	 * @return ServiceResponse This response contains a boolean to know if the folders has been synchronized
	 */
    public function synchronizeFoldersToCategories($idAccount)
	{
		$parameters = CoreCommons\Parameters::Singleton();
		$rootPath = $parameters::$Keys["DocumentsRootPath"];
	
		return $this->ICategories->synchronizeFoldersToCategories($idAccount, $rootPath);
	}
	
	/**
	 * Get user's tasks
	 * 
	 * @param integer $user The account unique identifier for user
	 *
	 * @return ServiceResponse This response contains all tasks
	 */
    public function getTasks($user)
	{
		return $this->ITasks->getTasks($user);
	}
	
	/**
	 * Get all tasks
	 *
	 * @return ServiceResponse This response contains all tasks
	 */
    public function getAllTasks()
	{
		return $this->ITasks->getAllTasks();
	}
	
	
	/**
	 * Delete the task by id
	 * 
	 * @param integer $id The task unique identifier
	 *
	 * @return ServiceResponse This response contains a boolean to know if the task has been deleted
	 */
    public function deleteTask($id)
	{
		return $this->ITasks->deleteTask($id);
	}
	
	/**
	 * Add a task
	 * 
	 * @param string $name The task name to add
	 *
	 * @return ServiceResponse This response contains the added task
	 */
	public function addTask($name, $user)
	{
		return $this->ITasks->addTask($name, $user);
	}
	
	/**
	* Update a task
	* 
	* @param integer $id The task unique identifier 
	* @param integer $status The task status
	*
	* @return This response contains the updated task
	*/
	public function updateTask($id, $status)
	{
		return $this->ITasks->updateTask($id, $status);
	}
	
	/*
	* Create a dump of the database
	*
	* @return ServiceResponse This response contains is the backup has been created
	*/
	public function createBackup()
	{
		CoreCommons\Logger::Info("BonoHomeCoreService - createDump");
		
		//Create a dump to prevent error
		$manageDump = new ManageDump();
		$result = $manageDump->CreateDump();
		
		$response = new ServiceResponse($result);
		
		return $response;
	}
	
	/*
	* Get the server configuration
	*
	* @return ServiceResponse This response contains the application configuration
	*/
	public function getConfiguration()
	{
		CoreCommons\Logger::Info("BonoHomeCoreService - getConfiguration");
		
		$parameters = CoreCommons\Parameters::Singleton();
		
		$response = new CoreCommons\ServiceResponse($parameters::$Keys);
		
		return $response;
	}
	
	/*
	* Reset the mapping
	*
	* @return ServiceResponse This response contains a boolean which inform if the reset is done.
	*/
	public function resetMappings()
	{
		CoreCommons\Logger::Info("BonoHomeCoreService - resetMapping");
		
		//Create a dump to prevent error
		$manageDump = new Datastorage\Tools\ManageDump();
		$manageDump->CreateDump();
		
		$parameters = CoreCommons\Parameters::Singleton();
		$databaseName = $parameters::$Keys["DataBaseName"];
		
		//Clear database
		$manageDump->DropDataBase($databaseName);
		
		//Create empty database
		$manageDump->CreateEmptyDataBase($databaseName);
		
		//Set generated table
		$resetMappings = new Datastorage\Tools\ResetMappings();
		$resetMappings ->Reset($databaseName);
		
		$response = new CoreCommons\ServiceResponse(true);
		
		return $response;
	}
	
	/*
	* Add package process
	*
	* @param string $version The package version
	*
	* @return ServiceResponse This response contains the package.
	*/
	public function createPackage($version)
	{
		CoreCommons\Logger::Info("BonoHomeCoreService - createPackage $version");
		
		$packageManager = new PackageManager();
		$package = $packageManager->CreatePackage($version);
		
		$response = new CoreCommons\ServiceResponse($package);
		
		return $response;
	}
	
	/*
	* Deploy package
	*
	* @param string $version The package version
	*
	* @return ServiceResponse
	*/
	public function deployPackage($package)
	{
		CoreCommons\Logger::Info("BonoHomeCoreService - deployPackage $package");
		
		$packageManager = new PackageManager();
		$package = $packageManager->DeployPackage($package);
		
		$response = new CoreCommons\ServiceResponse();
		
		return $response;
	}
	
	/*
	* Get the server configuration
	*
	* @return ServiceResponse This response contains all packages
	*/
	public function getPackages()
	{
		CoreCommons\Logger::Info("BonoHomeCoreService - getPackages");
		
		$packageManager = new PackageManager();
		$packages = $packageManager->GetPackages();
		
		$response = new CoreCommons\ServiceResponse($packages);
		
		return $response;
	}
	
	/*
	* Get parameters files list
	*
	* @return ServiceResponse This response contains all parameters files
	*/
	public function getParametersFiles()
	{
		CoreCommons\Logger::Info("BonoHomeCoreService - getParametersFiles");
		
		$parametersFiles = CoreCommons\Parameters::GetParametersFiles();
		
		$response = new CoreCommons\ServiceResponse($parametersFiles);
		
		return $response;
	}
	
	/*
	* Set a parameter file
	*
	* @param string $filename the filename  to set
	*
	* @return ServiceResponse This response contains the parameter file set
	*/
	public function SetParameterFile($filename)
	{
		CoreCommons\Logger::Info("BonoHomeCoreService - getParametersFiles");
		
		$parameterFile = CoreCommons\Parameters::SetParameterFile($filename);
		
		$response = new CoreCommons\ServiceResponse($parameterFile);
		
		return $response;
	}
	
	/*
	* Is the server available
	*/
	public function IsServerAvailable()
	{
		return new CoreCommons\ServiceResponse(true);
	}
	
	/*
	* Get translations 
	*
	* @return ServiceResponse This response contains all translations
	*/
	public function getTranslations()
	{
		CoreCommons\Logger::Info("Start to get translations");
		$localization = CoreCommons\Localization::Singleton();
		$result = $localization->GetTranslations();
		
		$response = new CoreCommons\ServiceResponse($result);
		
		return $response;
	}
	
	/**
	* Authenticate an user
	* 
	* @param string $login The user's login 
	* @param string $password The user's password 
	*
	* @return This response contains the use object
	*/
	public function authenticate($login, $password)
	{
		return $this->IUsers->authenticate($login, $password);
	}
	
	/*
	* Check the user authorization
	*
	* @param int $userid The user unique identifier
	*
	* @return ServiceResponse This response contains the user object or null
	*/
	public function checkUserAuthorization($userid)
	{
		$result = $this->IUsers->checkUserAuthorization($userid);
		
		//Update the user status online
		if($result->response != null)
		{
			$this->setUserAsOnline($userid);
		}
		else
		{
			$this->setUserAsOffline($userid);
		}
		
		return $result;
	}
	
	/**
	* Set an user as online
	*
	* @param int $userid The user unique identifier
	*
	* @return ServiceResponse This response contains the user object or null
	*/
	public function setUserAsOnline($userId)
	{
		return $this->IUsers->setUserAsOnline($userId);
	}
	
	/**
	* Get online users
	*
	* @return ServiceResponse This response contains all online users
	*/
	public function getOnlineUsers()
	{
		return $this->IUsers->getOnlineUsers();
	}
	
	/*
	* Reset user password
	*
	* @param int $userid The user unique identifier
	*
	* @return ServiceResponse This response contains the user object or null
	*/
	public function resetUserPassword($userid)
	{
		return $this->IUsers->resetUserPassword($userid);
	}
	
	/*
	* Set user as offline
	*
	* @param int $userid The user unique identifier
	*
	* @return ServiceResponse This response contains the user 
	*/
	public function setUserAsOffline($userid)
	{
		return $this->IUsers->setUserAsOffline($userid);
	}
	
	/**
	* Get all users
	*
	* @return This response contains all users
	*/
	public function getUsers()
	{
		return $this->IUsers->getUsers();
	}
	
	/*
	* Get an user
	*
	* @param int $id The user's identifier 
	*
	* @return ServiceResponse This response contains the user
	*/
	public function getUser($id)
	{
		return $this->IUsers->getUser($id);
	}
	
	/**
	* Get all user more or upper members
	*
	* @return ServiceResponse This response contains users
	*/
	public function getUsersMemberMinimum()
	{
		return $this->IUsers->getUsersMemberMinimum();
	}
	
	/*
	* Add an user
	*
	* @param string $firstname The user's firstname 
	* @param string $lastname The user's lastname 
	* @param string $email The user's email 
	* @param string $phonenumber The user's phonenumber 
	* @param int $profile The user's profile 
	*
	* @return ServiceResponse This response contains the added user
	*/
	public function addUser($firstname, $lastname, $company, $email, $phonenumber, $webaddress, $profile)
	{
		return $this->IUsers->addUser($firstname, $lastname, $company, $email, $phonenumber, $webaddress, (int)$profile);
	}
	
	/*
	* Add a new user
	*
	* @param string $firstname The user's firstname 
	* @param string $lastname The user's lastname 
	* @param string $email The user's email 
	*
	* @return ServiceResponse This response contains the added user
	*/
	public function addNewUser($firstname, $lastname, $email)
	{
		return $this->IUsers->addNewUser($firstname, $lastname, $email);
	}
	
	/*
	* Add a new member
	*
	* @param string $firstname The user's firstname 
	* @param string $lastname The user's lastname 
	* @param string $email The user's email 
	* @param string $object The user's object 
	* @param string $message The user's message 
	*
	* @return ServiceResponse This response contains the added user
	*/
	public function demandNewMember($firstname, $lastname, $email, $object, $message)
	{
		return $this->IUsers->demandNewMember($firstname, $lastname, $email, $object, $message);
	}
	
	/*
	* Send a contact mail
	*
	* @param string $firstname The user's firstname 
	* @param string $lastname The user's lastname 
	* @param string $email The user's email 
	* @param string $object The user's object 
	* @param string $message The user's message 
	*
	* @return ServiceResponse This response contains the added user
	*/
	public function sendContact($firstname, $lastname, $email, $object, $message)
	{
		return $this->IUsers->sendContact($firstname, $lastname, $email, $object, $message);
	}
	
	/*
	* Update an user
	*
	* @param int $id The unique identifier of a user
	* @param string $firstname The user's firstname 
	* @param string $lastname The user's lastname 
	* @param string $email The user's email 
	* @param string $phonenumber The user's phonenumber 
	* @param string $login The user's login 
	* @param string $password The user's password 
	* @param int $profile The user's profile 
	*
	* @return ServiceResponse This response contains the updated user
	*/
	public function updateUser($id, $firstname, $lastname, $company, $email, $phonenumber, $webaddress, $login, $profile)
	{
		return $this->IUsers->updateUser($id, $firstname, $lastname, $company, $email, $phonenumber, $webaddress, $login, (int)$profile);
	}
	
	/*
	* Update users's informations
	*
	* @param int $id The unique identifier of a user
	* @param string $firstname The user's firstname 
	* @param string $lastname The user's lastname 
	* @param string $email The user's email 
	* @param string $phonenumber The user's phonenumber 
	* @param string $login The user's login 
	*
	* @return ServiceResponse This response contains the updated user
	*/
	public function updateUserInformations($id, $firstname, $lastname, $company, $email, $phonenumber, $webaddress, $login)
	{
		return $this->IUsers->updateUserInformations($id, $firstname, $lastname, $company, $email, $phonenumber, $webaddress, $login);
	}
	
	/*
	* Update users's informations
	*
	* @param int $id The unique identifier of a user
	* @param string $newPassword The user's new password 
	*
	* @return ServiceResponse This response contains the updated user
	*/
	public function updateUserPassword($id, $newPassword)
	{
		return $this->IUsers->updateUserPassword($id, $newPassword);
	}
	
	/**
	* Attach a avatar on an user
	*
	* @param int $idUser The user id
	* @param binary[] $file The avatar file
	* @param string $mime The avatar file mime type
	* @param string $extension The avatar file extension
	* 
	* @return ServiceResponse This response contains the user with his avatar
	*/
	public function attachAvatarOnAnUser($idUser, $file, $mime, $extension)
	{
		return $this->IUsers->attachAvatarOnAnUser($idUser, $file, $mime, $extension);
	}
	
	/**
	* Get all profiles
	*
	* @return This response contains all profiles
	*/
	public function getProfiles()
	{
		return $this->IUsers->getProfiles();
	}
	
	/*
	* Delete an user
	*
	* @param int $id The user's identifier 
	*
	* @return ServiceResponse This response contains the added user
	*/
	public function deleteUser($id)
	{
		return $this->IUsers->deleteUser($id);
	}
	
	/*
	* valid an user
	*
	* @param string $password The user's password 
	*
	* @return ServiceResponse This response contains the validate user
	*/
	public function validUserEmail($password)
	{
		return $this->IUsers->validUserEmail($password);
	}
	
	/**
	* Get all articles
	*
	* @return This response contains all articles
	*/
	public function getArticles()
	{
		return $this->IArticles->getArticles();
	}
	
	/**
	* Get online articles
	*
	* @return This response contains all online articles
	*/
    public function getOnlinesArticles()
	{
		return $this->IArticles->getOnlinesArticles();
	}
	
	/**
	* Add an article
	*
	* @param string $title The article title
	* @param string $text The article content
	*
	* @return This response contains the added article
	*/
    public function addArticle($title, $text)
	{
		return $this->IArticles->addArticle($title, $text);
	}
	
	/**
	* Add a event
	*
	* @param string $title The event title
	* @param string $description The event description
	* @param datetime $startDate The start event date
	* @param datetime $endDate The end event date
	* @param int $numberOfPlace The number of places
	* @param string $location The event location
	* 
	* @return ServiceResponse This response contains the added event
	*/
	public function addEvent($title, $description, $startDate, $startTime, $endDate, $endTime, $numberOfPlaces, $location, $isSubscriptionValidationRequired)
	{
		$date = \DateTime::createFromFormat('d/m/Y', $startDate);
		$newStartDate = $date->format('Y-m-d');
		
		$date = \DateTime::createFromFormat('d/m/Y', $endDate);
		$newEndDate = $date->format('Y-m-d');

		return $this->IEvents->addEvent($title, $description, $newStartDate, $startTime, $newEndDate, $endTime, (int)$numberOfPlaces, $location, $isSubscriptionValidationRequired);
	}
	
	/**
	* Attach a poster on an event
	*
	* @param int $idEvent The event id
	* @param binary[] $file The poster file
	* 
	* @return ServiceResponse This response contains the event with his poster
	*/
	public function attachPosterOnAnEvent($idEvent, $file, $mime, $extension)
	{
		return $this->IEvents->attachPosterOnAnEvent($idEvent, $file, $mime, $extension);
	}
	
	/**
	* Attach an attachment on an event
	* 
	* @param integer $eventId The unique event identifier
	* @param binary[] $file The file content
	* @param string $mime The mime file
	* @param string $extension The extension file
	*
	* @return ServiceResponse This response contains the event attachment
	*/
	public function attachEventAttachment($eventId, $name, $file, $mime, $extension)
	{
		return $this->IEvents->attachEventAttachment($eventId, $name, $file, $mime, $extension);
	}
	
	/**
	* Get all event attachments
	* 
	* @param integer $eventId The unique event identifier
	*
	* @return ServiceResponse This response contains all event attachments
	*/
	public function getEventAttachments($eventId)
	{
		return $this->IEvents->getEventAttachments($eventId);
	}
	
	/** 
	* Pre subscribe an user to an event
	*
	* @param integer $userId The user who want to subscribe
	* @param integer $eventId The user event's want to participate
	*
	* @return ServiceResponse This response contains event subscription
	*/
	public function preSubscribe($userId, $eventId)
	{
		return $this->IEvents->preSubscribe($userId, $eventId);
	}
	
	/** 
	* Get all get all event subscriptions
	*
	* @return ServiceResponse This response contains all event subscription
	*/
	public function getEventSubscriptions()
	{	
		return $this->IEvents->getEventSubscriptions();
	}
	
	/** 
	* Get all personal events
	*
	* @return ServiceResponse This response contains all personal events
	*/
	public function getPersonalEvents($userId)
	{
		return $this->IEvents->getPersonalEvents($userId);
	}
	
	/** 
	* Set user as partner on an event subscription
	*
	* @return ServiceResponse This response contains event subscription
	*/
	public function userIsPartner($eventSubscriptionId, $isPartner)
	{
		return $this->IEvents->userIsPartner($eventSubscriptionId, $isPartner);
	}
	
	/**
	* Get all participants on an event
	* 
	* @param integer $id The event id
	*
	* @return ServiceResponse This response contains all participants
	*/
    public function getParticipants($id)
	{
		return $this->IEvents->getParticipants($id);
	}
	
	/** 
	* Get all event subscriptions validate for planned event
	*
	* @return ServiceResponse This response contains all valid event subscription for planned event
	*/
	public function getValidEventSubscriptionsForPlannedEvent()
	{	
		return $this->IEvents->getValidEventSubscriptionsForPlannedEvent();
	}
	
	/** 
	* Get all event subscriptions to valid
	*
	* @return ServiceResponse This response contains all event subscription to valid
	*/
	public function getEventSubscriptionsToValid()
	{	
		return $this->IEvents->getEventSubscriptionsToValid();
	}
	
	/** 
	* Update the event subscription event subscriptions
	*
	* @param integer $id The event subscription id
	* @param integer $state The event subscription new state
	*
	* @return ServiceResponse This response contains all event subscription
	*/
	public function updateEventSubscription($id, $state)
	{
		return $this->IEvents->updateEventSubscription($id, $state);
	}
	
	/**
	* Get all event states
	*
	* @return ServiceResponse This response contains all states event
	*/
	public function getEventSubscriptionStates()
	{
		return $this->IEvents->getEventSubscriptionStates();
	}
	
	/**
	* Get all events
	* 
	* @return ServiceResponse This response contains all events
	*/
    public function getEvents()
	{
		return $this->IEvents->getEvents();
	}
	
	/**
	* Get all event states
	*
	* @return ServiceResponse This response contains all states event
	*/
	public function getEventStates()
	{
		return $this->IEvents->getStates();
	}
	
	/**
	* Get all archives event
	*
	* @param integer $id The event id
	*
	* @return ServiceResponse This response contains all archives event
	*/
	public function getArchivesEvent($id)
	{
		return $this->IEvents->getArchivesEvent($this->archiveRootPath, $id);
	}
	
	/**
	* Get all online events
	* 
	* @return ServiceResponse This response contains all online events
	*/
    public function getOnlineEvents()
	{
		return $this->IEvents->getOnlineEvents();
	}
	
	/**
	* Get all done events
	* 
	* @return ServiceResponse This response contains all done events
	*/
    public function getDoneEvents()
	{
		return $this->IEvents->getDoneEvents();
	}
	
	/**
	* Delete an event
	* 
	* @param integer $id The unique event identifier
	*
	* @return ServiceResponse This response contains the deleted event
	*/
	public function deleteEvent($id)
	{
		return $this->IEvents->deleteEvent($id);
	}
	
	/**
	* Update an event
	* 
	* @param integer $id The unique event identifier
	* @param string $title The event title
	* @param string $description The event description
	* @param datetime $startDate The start event date
	* @param datetime $endDate The end event date
	* @param int $numberOfPlaces The number of places
	* @param string $archiveName The end event date
	* @param int $state The event state
	* @param string $location The event location
	*
	* @return ServiceResponse This response contains the updated event
	*/
	public function updateEvent($id, $title, $description, $startDate, $startTime, $endDate, $endTime, $numberOfPlaces, $archiveName, $state, $location)
	{
		$date = \DateTime::createFromFormat('d/m/Y', $startDate);
		$newStartDate = $date->format('Y-m-d');
		
		$date = \DateTime::createFromFormat('d/m/Y', $endDate);
		$newEndDate = $date->format('Y-m-d');
	
		return $this->IEvents->updateEvent($id, $title, $description, $newStartDate, $startTime, $newEndDate, $endTime, (int)$numberOfPlaces, $archiveName, $state, $location);
	}
	
	/**
	* Attach an archive to an event
	* 
	* @param integer $id The unique event identifier
	* @param string $archiveName The archive folder name
	*
	* @return ServiceResponse This response contains the deleted event
	*/
	public function attachArchive($idEvent, $archiveName)
	{
		return $this->IEvents->attachArchive($idEvent, $archiveName);
	}
	
	/**
	* Plan an event
	* 
	* @param integer $id The unique event identifier
	*
	* @return ServiceResponse This response contains the planned event
	*/
	public function planEvent($id)
	{
		return $this->IEvents->planEvent($id);
	}
	
	/**
	* Close subscriptions on an event
	* 
	* @param integer $id The unique event identifier
	*
	* @return ServiceResponse This response contains the closed subscriptions event
	*/
	public function closeSubscriptionsEvent($id)
	{
		return $this->IEvents->closeSubscriptionsEvent($id);
	}
	
	/**
	* Run an event
	* 
	* @param integer $id The unique event identifier
	*
	* @return ServiceResponse This response contains the running event
	*/
	public function runEvent($id)
	{
		return $this->IEvents->runEvent($id);
	}
	
	/**
	* Cancel an event
	* 
	* @param integer $id The unique event identifier
	*
	* @return ServiceResponse This response contains the cancelled event
	*/
	public function cancelEvent($id)
	{
		return $this->IEvents->cancelEvent($id);
	}
	
	/**
	* Done an event
	* 
	* @param integer $id The unique event identifier
	*
	* @return ServiceResponse This response contains the done event
	*/
	public function doneEvent($id)
	{
		return $this->IEvents->doneEvent($id);
	}
	
	/**
	 * Add a tchat message
	 *
	 * @param string $message The tchat message
	 * @param User $user The sender (user id)
	 * 
	 * @return ServiceResponse This response contains the added tchat message
	 */
	public function addTchatMessage($message, $user)
	{
		return $this->ITchats->addTchatMessage($message, $user);
	}
	
	/**
	 * Get all tchat messages
	 * 
	 * @return ServiceResponse This response contains all tchat messages
	 */
    public function getTchatMessages()
	{
		return $this->ITchats->getTchatMessages();
	}
	
	/**
	 * Delete all message from tchat
	 *
	 * @return ServiceResponse This response contains the deleted messages
	 */
	public function deleteAllMessages()
	{
		return $this->ITchats->deleteAllMessages();
	}
	
	/**
	* Get all materials
	*
	* @return This response contains all materials
	*/
    public function getMaterials()
	{
		return $this->IMaterials->getMaterials();
	}
	
	/**
	* Get all material states
	*
	* @return ServiceResponse This response contains all states material
	*/
	public function getMaterialStates()
	{
		return $this->IMaterials->getStates();
	}
	
	/**
	* Add a material
	*
	* @param int $state The material state
	* @param string $name The material name
	* @param string $description The material description
	* @param User $affectedUser The affected user which have the material
	* @param string $location The material location
	*
	* @return This response contains the added material
	*/
    public function addMaterial($state, $name, $description, $affectedUser, $location)
	{
		return $this->IMaterials->addMaterial($state, $name, $description, $affectedUser, $location);
	}
	
	/**
	* Update a material
	*
	* @param int $id The material unique identifier to update
	* @param int $state The material state
	* @param string $name The material name
	* @param string $description The material description
	* @param User $affectedUser The affected user which have the material
	* @param string $location The material location
	*
	* @return This response contains the added material
	*/
    public function updateMaterial($id, $state, $name, $description, $affectedUser, $location)
	{
		return $this->IMaterials->updateMaterial($id, $state, $name, $description, $affectedUser, $location);
	}
	
	/**
	* Delete a material
	* 
	* @param integer $id The unique material identifier
	*
	* @return ServiceResponse This response contains the deleted material
	*/
	public function deleteMaterial($id)
	{
		return $this->IMaterials->deleteMaterial($id);
	}
}
?>